home *** CD-ROM | disk | FTP | other *** search
/ Aminet 5 / Aminet 5 - March 1995.iso / Aminet / comm / tcp / ATCP_src_22.lha / AmiTCP-2.2 / src / amitcp / sys / malloc.h < prev    next >
Encoding:
C/C++ Source or Header  |  1993-08-12  |  5.6 KB  |  170 lines

  1. /*
  2.  * $Id: malloc.h,v 1.13 1993/05/16 23:15:36 ppessi Exp $
  3.  *
  4.  * HISTORY
  5.  * $Log: malloc.h,v $
  6.  * Revision 1.13  1993/05/16  23:15:36  ppessi
  7.  * Added M_ARPENT
  8.  *
  9.  * Revision 1.12  1993/04/28  22:09:44  ppessi
  10.  * Added M_CFGVAR and M_NETDB as new memory types.
  11.  *
  12.  * Revision 1.11  93/03/11  19:40:33  19:40:33  jraja (Jarno Tapio Rajahalme)
  13.  * Changed mallocSemaphore to malloc_semaphore.
  14.  * 
  15.  * Revision 1.10  93/03/11  12:27:44  12:27:44  jraja (Jarno Tapio Rajahalme)
  16.  * Minor Clean up.
  17.  * 
  18.  * Revision 1.9  93/03/03  19:35:24  19:35:24  jraja (Jarno Tapio Rajahalme)
  19.  * Cleanup. Removed redundant memory types, changed _MALLOC_H_ to SYS_MALLOC_H.
  20.  * 
  21.  * Revision 1.8  93/02/27  12:07:44  12:07:44  ppessi (Pekka Pessi)
  22.  * Added memory type for network interface (M_IFNET)
  23.  * 
  24.  * Revision 1.7  93/02/27  12:05:52  12:05:52  jraja (Jarno Tapio Rajahalme)
  25.  * Added #include <cdefs.h> for inline functions.
  26.  * 
  27.  * Revision 1.6  93/02/24  12:56:09  12:56:09  jraja (Jarno Tapio Rajahalme)
  28.  * Changed malloc_init prototype.
  29.  * 
  30.  * Revision 1.5  93/02/24  11:15:41  11:15:41  jraja (Jarno Tapio Rajahalme)
  31.  * Changed path uxkern to kern.
  32.  * 
  33.  * Revision 1.4  93/01/23  22:21:32  22:21:32  jraja (Jarno Tapio Rajahalme)
  34.  * Protected calls to malloc() & free() with a semaphore (because they are
  35.  * not re-entrant).
  36.  * 
  37.  * Revision 1.3  93/01/06  19:11:56  19:11:56  jraja (Jarno Tapio Rajahalme)
  38.  * Removed all definitions related to virtual memory subsystem.
  39.  * Added inline definitions for bsd_malloc and bsd_free.
  40.  * 
  41.  * Revision 1.2  92/11/20  15:56:56  15:56:56  jraja (Jarno Tapio Rajahalme)
  42.  * Added #ifndef AMITCP's to make this compile.
  43.  * 
  44.  * Revision 1.1  92/11/20  15:47:59  15:47:59  jraja (Jarno Tapio Rajahalme)
  45.  * Initial revision
  46.  */
  47.  
  48. /*
  49.  * Copyright (c) 1987 Regents of the University of California.
  50.  * All rights reserved.
  51.  *
  52.  * Redistribution and use in source and binary forms, with or without
  53.  * modification, are permitted provided that the following conditions
  54.  * are met:
  55.  * 1. Redistributions of source code must retain the above copyright
  56.  *    notice, this list of conditions and the following disclaimer.
  57.  * 2. Redistributions in binary form must reproduce the above copyright
  58.  *    notice, this list of conditions and the following disclaimer in the
  59.  *    documentation and/or other materials provided with the distribution.
  60.  * 3. All advertising materials mentioning features or use of this software
  61.  *    must display the following acknowledgement:
  62.  *    This product includes software developed by the University of
  63.  *    California, Berkeley and its contributors.
  64.  * 4. Neither the name of the University nor the names of its contributors
  65.  *    may be used to endorse or promote products derived from this software
  66.  *    without specific prior written permission.
  67.  *
  68.  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  69.  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  70.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  71.  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  72.  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  73.  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  74.  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  75.  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  76.  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  77.  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  78.  * SUCH DAMAGE.
  79.  *
  80.  *    @(#)malloc.h    7.25 (Berkeley) 5/15/91
  81.  */
  82.  
  83. #ifndef SYS_MALLOC_H
  84. #define    SYS_MALLOC_H
  85.  
  86. /*
  87.  * flags to malloc
  88.  */
  89. #define    M_WAITOK    0x0000
  90. #define    M_NOWAIT    0x0001
  91.  
  92. /*
  93.  * Types of memory to be allocated
  94.  */
  95. #define    M_FREE        0    /* should be on free list */
  96. #define    M_MBUF        1    /* mbuf */
  97. #define    M_SOCKET    2    /* socket structure */
  98. #define    M_PCB        3    /* protocol control block */
  99. #define    M_RTABLE    4    /* routing tables */
  100. #define    M_HTABLE    5    /* IMP host tables */
  101. #define    M_FTABLE    6    /* fragment reassembly header */
  102. #define    M_IFADDR    7    /* interface address */
  103. #define    M_SOOPTS    8     /* socket options */
  104. #define    M_SONAME    9     /* socket name */
  105. #define    M_IOCTLOPS    10    /* ioctl data buffer */
  106. #define    M_FILEDESC    11    /* Open file descriptor table */
  107. #define    M_TEMP        12    /* misc temporary data buffers */
  108. #define    M_IFNET        13    /* network interface structure */
  109. #define M_CFGVAR     14    /* configureable variable */
  110. #define M_NETDB      15    /* netdb node */
  111. #define M_ARPENT        16    /* ARP entry */
  112. #define    M_LAST        17
  113.  
  114. #ifdef KERNEL
  115.  
  116. /*
  117.  * Use malloc & free of the standard library.
  118.  *
  119.  * NOTE: Because these are called from different tasks concurrently, these
  120.  * have to be protected with a mutex.
  121.  */
  122. #ifndef AMIGA_INCLUDES_H
  123. #include <kern/amiga_includes.h>
  124. #endif
  125.  
  126. #ifndef SYS_CDEFS_H
  127. #include <sys/cdefs.h>
  128. #endif
  129.  
  130. /*
  131.  * prototype for the initialization function
  132.  */
  133. extern BOOL malloc_init(void);
  134.  
  135. static inline void *
  136. bsd_malloc(unsigned long size, int type, int flags)
  137. {
  138.   register void *mem;
  139.  
  140.   extern void *malloc(size_t);
  141.   extern struct SignalSemaphore malloc_semaphore; 
  142.  
  143.   ObtainSemaphore(&malloc_semaphore);
  144.   mem = malloc((size_t)size);
  145.   ReleaseSemaphore(&malloc_semaphore);
  146.  
  147.   return mem;
  148. }
  149.  
  150. static inline void
  151. bsd_free(void *addr, int type)
  152. {
  153.   extern void free(void *);
  154.   extern struct SignalSemaphore malloc_semaphore; 
  155.  
  156.   ObtainSemaphore(&malloc_semaphore);
  157.   free(addr);
  158.   ReleaseSemaphore(&malloc_semaphore);
  159. }
  160.  
  161. /*
  162.  * Macro versions for the usual cases of malloc/free
  163.  */
  164. #define    MALLOC(space, cast, size, type, flags) \
  165.     (space) = (cast)bsd_malloc((u_long)(size), type, flags)
  166. #define FREE(addr, type) bsd_free((caddr_t)(addr), type)
  167.  
  168. #endif /* KERNEL */
  169. #endif /* !SYS_MALLOC_H */
  170.